home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / Common / CDSSpec.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  7.3 KB  |  287 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CDSSpec
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>    10/14/94    TMH        added CDSSpec constructor
  13.          <2>     9/27/94    TMH        added CUnpackedDSSpec assignment operator
  14.          <1>     9/20/94    TMH        Abandon RoadsideRest embrace Mercury
  15.          <2>      9/9/94    TMH        added constructor to CUnpackedDSSpec
  16.                  6/10/94    TMH        xxx put comment here xxx
  17.  
  18.     To Do:
  19. */
  20.  
  21. #ifndef __STDIO__
  22. #include "StdIO.h"
  23. #endif
  24.  
  25. #ifndef __CDSSpec__
  26. #include "CDSSpec.h"
  27. #endif
  28.  
  29. #ifndef __PMSAMResourceIds__
  30. #include "PMSAMResourceIds.h"
  31. #endif
  32.  
  33. #ifndef __PMSAMResources__
  34. #include "PMSAMResources.h"
  35. #endif
  36.  
  37.  
  38.  
  39. //----------------------------------------
  40. //            C U n p a c k e d D S S p e c 
  41. //----------------------------------------
  42.  
  43.  
  44. //--------------------------------------------------------------------------
  45. CUnpackedDSSpec& CUnpackedDSSpec::operator =(OCEPackedRecipient* packedRecipient) 
  46.     OCEUnpackDSSpec((PackedDSSpec*)packedRecipient,(DSSpec*)this,fEntitySpecifier);
  47.     return *this;  
  48. };
  49.  
  50. //--------------------------------------------------------------------------
  51. CUnpackedDSSpec::CUnpackedDSSpec(OCEPackedRecipient* packedRecipient)
  52. {
  53.     fEntitySpecifier = &fEntity;
  54.     OCEUnpackDSSpec((PackedDSSpec*)packedRecipient,(DSSpec*)this,fEntitySpecifier);
  55.  
  56. }
  57.  
  58. //--------------------------------------------------------------------------
  59. // for decodeing dialup phone number string
  60. struct    UnpackedPhAddr {
  61.     short    viewType;
  62.     Str31    CC;
  63.     Str31    AC;
  64.     Str31    phNum;
  65.     Str31    postfix;
  66.     char    directDial[128];
  67. };
  68. #ifndef    __cplusplus
  69. typedef struct UnpackedPhAddr UnpackedPhAddr;
  70. #endif
  71.  
  72. #define InlineCode(selector) = { 0x303C, selector, 0xAA5C}
  73. #define sDialupUnpackPhAddr            1282
  74. pascal Boolean    DialupUnpackPhAddr(RString* RSPtr, UnpackedPhAddr* ph) InlineCode(sDialupUnpackPhAddr);
  75.  
  76. #define        kTemplateView                1
  77. #define        kIKnowView                    2
  78.  
  79.  
  80. //--------------------------------------------------------------------------
  81. StringPtr CUnpackedDSSpec::ExtValue(short asType, Ptr buffer)
  82. {
  83.     CDirExtTypeTableIterator    iter(kDirExtTypeTableID);
  84.     StringPtr otherRecipient = (StringPtr)buffer;
  85.     
  86.     DirExtTypeEntry* defaultDirExtType = 0;
  87.      
  88.     otherRecipient[0] = 0;
  89.     
  90.     for( DirExtTypeEntry* dirExtType = iter.FirstDirExtType();iter.More(); dirExtType = iter.NextDirExtType() ) {
  91.     
  92.         defaultDirExtType = dirExtType;
  93.         
  94.         if( fExtType == dirExtType->extType ) {
  95.         
  96.             if( dirExtType->isRString )
  97.                 otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P", &dirExtType->dirSysName, ExtValue() );
  98.             else
  99.             {
  100.                 switch (fExtType)
  101.                 {
  102.                     case 'entn':
  103.                         otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P",&dirExtType->dirSysName, (StringPtr)EntityName());
  104.                         break;
  105.                     
  106.                     case 'aphn':
  107.                         UnpackedPhAddr upPhone;
  108.  
  109.                         if (DialupUnpackPhAddr((RString *)fExtValue, &upPhone))
  110.                         {
  111.                             if (upPhone.viewType == kTemplateView)
  112.                                 otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P%P%P",&dirExtType->dirSysName, 
  113.                                                 (StringPtr)upPhone.CC, (StringPtr)upPhone.AC, (StringPtr)upPhone.phNum);
  114.                             else
  115.                                 otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P",&dirExtType->dirSysName, 
  116.                                                 (StringPtr)upPhone.directDial);
  117.                         }
  118.                         
  119.                         break;
  120.                         
  121.                     case 'TFAX':
  122.                     
  123.                         // this is what I think the TFAX extension compound rstring format is:
  124.                         //      long  - not used, usually 0 (0 length rstring???)
  125.                         //         RString - country code
  126.                         //        RString - area code
  127.                         //         RString - phone number
  128.                         
  129.                         
  130.                         // skip the first unused long, move the point to the body of ext value rstring where the first rstring is
  131.                         Ptr ext = (Ptr)fExtValue;
  132.                         ext = (Ptr)&(((RStringPtr)ext) -> body[0]);
  133.                         StringPtr cc,ac,ph;
  134.                         
  135.                             cc = OCERToPString((RStringPtr)ext);
  136.                             
  137.                             // point to next rstring
  138.                             ext = ext+ ((RStringPtr)ext) -> dataLength + sizeof(ProtoRString);
  139.                             if (cc[0] % 2)        // odd number string, skip the padding
  140.                                 ext += 1;
  141.                         
  142.                             ac = OCERToPString((RStringPtr)ext);
  143.                             
  144.                             // point to next rstring
  145.                             ext = ext+ ((RStringPtr)ext) -> dataLength + sizeof(ProtoRString);
  146.                             if (ac[0] % 2)        // odd number string, skip the padding
  147.                                 ext += 1;
  148.                         
  149.                             ph = OCERToPString((RStringPtr)ext);
  150.                         
  151.                             // put them in buffer
  152.                             otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P%P%P",&dirExtType->dirSysName, 
  153.                                                 (StringPtr)cc, (StringPtr)ac, (StringPtr)ph);
  154.                         break;
  155.  
  156.                     default:
  157.                         break;
  158.                 }
  159.             }
  160.             break;
  161.         
  162.         }
  163.     
  164.     }
  165.  
  166. //    ASSERT(defaultDirExtType);
  167.     
  168.     if( (defaultDirExtType!=0) && (otherRecipient[0] == 0) ) {
  169. //        ASSERTPRINT(false,("MapOtherAddress unknown extType %.4s\n",&unpackedRecipient.fExtType) );
  170.         otherRecipient[0] = sprintf((char*)&otherRecipient[1],"%P%P",&defaultDirExtType->dirSysName, (StringPtr)EntityName());
  171.     
  172.     }
  173.     
  174.     
  175.     return otherRecipient;
  176.     
  177. }
  178.  
  179. //--------------------------------------------------------------------------
  180. StringPtr CUnpackedDSSpec::ExtValue()
  181. {
  182.  
  183.     switch(fExtType) {
  184.     case 'alan':
  185.         return (StringPtr)fExtValue;
  186.     case 'entn': {
  187.         CUnpackedDSSpec    mailServer((OCEPackedRecipient*)(fExtValue + sizeof(OSType)));
  188.         return mailServer.EntityName();
  189.         }
  190.     default:
  191.         return (StringPtr) *(CRString*)fExtValue;    // assume its an RString
  192.     }
  193.  
  194. }
  195.  
  196.  
  197.  
  198.  
  199. //---------------------------------
  200. //        C D S S p e c
  201. //---------------------------------
  202.  
  203. //  some of these may not be used anymore.
  204.  
  205. //-------------------------------------------------------------------------------------------
  206. CDSSpec::CDSSpec(StringPtr name,StringPtr dirName, OSType extType,StringPtr extValue )
  207. {
  208.     fExtValue = (Ptr)&_fExtValue;
  209.     
  210.     fEntitySpecifier = &fEntity;
  211.     
  212.     CRLI recipientRLI(dirName,extType);
  213.     OCEPackRLI((RLI*)&recipientRLI,(PackedRLI*)fEntity.fRLI,sizeof(CPackedRLI));
  214.  
  215.     fEntity.SetType(kUserRecTypeNum);
  216.     fEntity.SetName(name);
  217.  
  218.     fExtType = extType;
  219.     _fExtValue = extValue;
  220.     fExtSize = _fExtValue.Length();
  221. }
  222.  
  223.  
  224.  
  225. //-------------------------------------------------------------------------------------------
  226. CDSSpec::CDSSpec(CRecordName& name,StringPtr dirName, OSType extType,StringPtr extValue )
  227. {
  228.     fExtValue = (Ptr)&_fExtValue;
  229.     
  230.     fEntitySpecifier = &fEntity;
  231.     
  232.     CRLI recipientRLI(dirName,extType);
  233.     OCEPackRLI((RLI*)&recipientRLI,(PackedRLI*)fEntity.fRLI,sizeof(CPackedRLI));
  234.  
  235.     fEntity.SetType(kUserRecTypeNum);
  236.     fEntity.SetName(name);
  237.  
  238.     fExtType = extType;
  239.     _fExtValue = extValue;
  240.     fExtSize = _fExtValue.Length();
  241. }
  242.  
  243.  
  244. //-----------------------------------------------------------------------------------------
  245. CDSSpec::CDSSpec(StringPtr name,CDirectoryName& dirName,OSType extType,StringPtr extValue)
  246. {
  247.     fExtValue = (Ptr)&_fExtValue;
  248.     
  249.     fEntitySpecifier = &fEntity;
  250.     
  251.     CRLI recipientRLI(dirName,extType);
  252.     OCEPackRLI((RLI*)&recipientRLI,(PackedRLI*)fEntity.fRLI,sizeof(CPackedRLI));
  253.  
  254.     fEntity.SetType(kUserRecTypeNum);
  255.     fEntity.SetName(name);
  256.  
  257.     fExtType = extType;
  258.     _fExtValue = extValue;
  259.     fExtSize = _fExtValue.Length();
  260. }
  261.  
  262.  
  263.  
  264. //-------------------------------------------------------------------------------------------
  265. CDSSpec::CDSSpec(OCEPackedRecipient* packedRecipient )
  266. {
  267.     RecordID    rid;
  268.     DSSpec        dsspec;
  269.  
  270.     OCEUnpackDSSpec((PackedDSSpec*)packedRecipient,&dsspec,&rid);
  271.     
  272.     fEntitySpecifier = &fEntity;
  273.  
  274.     //    We copy into this
  275.     
  276.     fEntity = &rid;    // copy
  277.     
  278.     fExtType = dsspec.extensionType;
  279.     fExtSize = dsspec.extensionSize;
  280.     
  281.     _fExtValue = (RString*)dsspec.extensionValue;    // assumption of string.
  282. }
  283.  
  284.  
  285.  
  286.